<?PHP
// Our custom comment rendering
if(!function_exists('op_comment_start')){
function op_comment_start($comment, $args, $depth){
		$GLOBALS['comment'] = $comment;

		if ( 'div' == $args['style'] ) {
			$tag = 'div';
			$add_below = 'comment';
		} else {
			$tag = 'li';
			$add_below = 'div-comment';
		}
		
		$author_class = get_the_author() == $comment->comment_author ? 'is_author' : '';
		
		echo '<'.$tag.' '; comment_class($author_class); echo ' id="comment-'; comment_ID(); echo '">';
		if ( 'ul' == $args['style'] ){
			echo '<div id="div-comment-'; comment_ID(); echo '">';
		}

		echo '<div class="comment-author vcard">';
			
		if ($args['avatar_size'] != 0)
			echo get_avatar( $comment, $args['avatar_size'] );
		printf(__('<cite>%s</cite> Says:'), get_comment_author_link());

		echo '</div>';

		if ($comment->comment_approved == '0'){
			echo '<em>'; _e('Your comment is awaiting moderation.'); echo '</em>';
			echo '<br />';
		}

		echo '<div class="comment-meta commentmetadata"><a href="#comment-'; comment_ID(); echo'" title="">';
			printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'),  get_comment_time());
			echo '</a>';
			edit_comment_link('edit','&nbsp;&nbsp;','');
			echo '</div>';

		echo apply_filters('comment_text', get_comment_text());

		echo '<div class="reply">';
		echo comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['depth'])));
		if ( 'ul' == $args['style'] ){
			echo '</div>';
		}
		
		echo '</div>';
}
}

if(!function_exists('op_comment_end')){
function op_comment_end(){
}
}

if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
	die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) {
	echo 'This post is password protected. Enter the password to view comments.';
	return;
}

if ( have_comments() ) : ?>
<h4 id="comments"><?php comments_number('No Comments', 'One Comment', '% Comments' );?></h4>
<ul class="commentlist">
	<?php wp_list_comments('callback=op_comment_start&end-callback=op_comment_end'); ?></ul>
<div class="navigation">
<div class="alignleft"><?php previous_comments_link() ?></div>
<div class="alignright"><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
	<?php if ('open' == $post->comment_status) :
		// If comments are open, but there are no comments.
	else : // comments are closed
	endif;
endif;

if ('open' == $post->comment_status) : ?>

<div id="respond">
<?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?>
<div id="cancel-comment-reply">
	<small><?php cancel_comment_reply_link() ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>

<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

<?php if ( $user_ID ) :
	global $wp_version;
	preg_match('/([0-9\.]+)/',$wp_version,$version);
	
	// Get current version and create logout link based on version
	if($version[0] >= 2.7){
		$logout_link = '<a href="'.wp_logout_url().'">'.__('Logout').'</a>';
	}
	else if($version[0] >= 2.6){
		$logout_link = '<a href="'.site_url('/wp-login.php?action=logout', 'admin').'">'.__('Logout').'</a>';
	}
	else{
		$logout_link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
	}
	
?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <?php echo $logout_link; ?></p>

<?php else : ?>

<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>

<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>

<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>

<?php endif; ?>

<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>

<?php endif; // If registration required and not logged in ?>

</div>

<?php endif; // if you delete this the sky will fall on your head 

?>